define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'procurement.rule/index',
        add_url: 'procurement.rule/add',
        edit_url: 'procurement.rule/edit',
        delete_url: 'procurement.rule/delete',
        export_url: 'procurement.rule/export',
        modify_url: 'procurement.rule/modify',
        import_url:'procurement.rule/import',
        template:'procurement.rule/template',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh', 'add', 'delete', 'import',
                    [{
                        text: '导入',
                        url: init.import_url,
                        method: 'open',
                        auth: 'import',
                        class: 'layui-btn layui-btn-sm',
                        icon: 'fa fa-plus ',
                        extend: 'data-full="true"',
                    }], 'export'],


                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: '主键'},
                    {field: 'name', title: '规则名称'},
                    {field: 'create_time', title: '创建名称'},
                    {width: 250, title: '操作', templet: ea.table.tool},

                ]],
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
        import: function () {
            // 初始化分区上传
            var params = { id: 'upload-file', url: init.import_url, type: 0 };
            ea.file.upload(params);

            // 选项卡监听上传
            var element = layui.element;
            element.on('tab(table-box)', function (data) {
                console.log(data);
                var id = $('.layui-show').find('.upload-file').attr('id');
                params.id = id;
                params.type = data.index;
                ea.file.upload(params);
            });

        },

    };
    return Controller;
});